package mypack.threadtest;


public class BlockingTest {

	public static void main(String[] args) {

		final BlockingQuery query = new BlockingQuery(10);
		//final BlockingQueue<Object> query = new ArrayBlockingQueue<Object>(10);
		/**
		 * 同时启动1000个线程放对象
		 * 
		 */
		for (int i = 0; i < 1000; i++) {
			final int seq = i;
			new Thread(new Runnable() {

				@Override
				public void run() {

					try {
						query.put("INDEX==" + seq);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}).start();

		}

		/**
		 * 
		 * 同时启动1000个线程读取数据
		 * 
		 */
		for (int i = 0; i < 1000; i++) {
			new Thread(new Runnable() {
				@Override
				public void run() {
                    try {
						Object obj = query.take();
                        System.out.println(obj.toString());
                    } catch (InterruptedException e) {
						e.printStackTrace();
					}
                    
				}
			}
			).start();

		}

	}

}
